package com.googlecode.vanaraha.eclipse.preferences

import org.eclipse.jface.preference._
import org.eclipse.ui.{IWorkbench, IWorkbenchPreferencePage}

trait VWorkBenchPreferencePage extends IWorkbenchPreferencePage{
  protected var workbench: IWorkbench = _
  override def init(workBench: IWorkbench) = this.workbench = workBench 
}

abstract class VPreferencePage extends FieldEditorPreferencePage(FieldEditorPreferencePage.GRID){
  def +=(fieldEditor: FieldEditor) = addField(fieldEditor)
  def +?(name: String, desc: String) = this.addField(new BooleanFieldEditor(name, desc, getFieldEditorParent))
  def ++?(map: Map[String, String]) = for(mapEntry <- map) +?(mapEntry._1, mapEntry._2)
  setPreferenceStore(Activator.preferences)
}

class SimianPreferencePage extends VPreferencePage
	with VWorkBenchPreferencePage{
	import ToolConstants.Simian.constant
    setDescription("Simian Preferences")

    override def createFieldEditors{
      val intEditor = new IntegerFieldEditor(constant.simianThreshold,
      							"Minimum number of duplicate lines(threshold):  ", getFieldEditorParent)
      intEditor setValidRange(7, 100)
      addField(intEditor)
      
      ++?(Map ( constant.balanceCurlyBraces    -> "Balance Curly Braces",
			   constant.balanceParentheses    -> "Balance Parentheses",
			   constant.balanceSquareBrackets -> "Balance Square Brackets",
			   constant.ignoreCharacterCase   -> "Ignore Character Case",
			   constant.ignoreCharacters      -> "Ignore Characters",
			   constant.ignoreCurlyBraces     -> "Ignore Curly Braces",
			   constant.ignoreIdentifierCase  -> "Ignore Identifier Case"))
    }
    
} 
 
class VanarahaPreferencePage extends VPreferencePage
	with VWorkBenchPreferencePage{
  import Activator.constant
  
  override def createFieldEditors{
    +=(new RadioGroupFieldEditor(constant.toolToFindDuplicates, "Select tool used to find duplicates", 1,
                                Array(Array("Simian", constant.default.toolToFindDuplicates)), getFieldEditorParent))
    +?(constant.limitMarkerAddition, "Do not add more than 100 markers in a single file")
    +?(constant.donotMarkRangeOfLines, "Do not mark range of lines which are duplicates")
    +=(new StringFieldEditor(constant.fileExtension, "File Extension : ", getFieldEditorParent))
  }
  
}